package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "C端-套餐接口")
public class SetmealController
{

    @Autowired
    private SetmealService setmealService;
    //根据分类id查询套餐列表
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> setmealList(@RequestParam(value = "categoryId") String categoryId){
        //根据我们传进去的条件进行动态条件查询
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(Long.valueOf(categoryId));
        setmeal.setStatus(StatusConstant.ENABLE);

        List<Setmeal> setmealList = setmealService.getList(setmeal);
       return Result.success(setmealList);
    }


    //根据套餐id查询套餐菜品列表
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> setmealDish(@PathVariable(value = "id") String setmealId){
       List<DishItemVO> SDList = setmealService.setmealDish(setmealId);
       return Result.success(SDList);

    }
}
